import { defineStore } from "pinia";

const getTempHouseData = () => ({
  house_id: null,
  code: "",
  name: "",
  type: 1,
  condition: 1,
  user_id: null,
  contact_phone: "",
  address: "",
  notes: "",
  status: 1,
});

export const HouseTempStore = defineStore("houseTemp", {
  state: () => ({
    tempFormData: getTempHouseData(),
  }),

  actions: {
    saveTempData(data) {
      this.tempFormData = JSON.parse(JSON.stringify(data));
    },

    clearTempData() {
      this.tempFormData = getTempHouseData();
    },
  },

  persist: {
    key: "house-form-temp-data",
    storage: localStorage,
  },
});
